package com.dailycodebuffer.springbootmongodb.controller;

import com.dailycodebuffer.springbootmongodb.collection.Orders;
import com.dailycodebuffer.springbootmongodb.service.OrdersService;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;


/**
 * 控制层
 *
 * @author makejava
 * @since 2025-01-04 00:23:42
 */
@RestController
@RequestMapping("/orders")
@AllArgsConstructor
public class OrdersController {

	private OrdersService ordersService;

	/**
	 * 获取列表(分页)
	 */
	@GetMapping("/list")
	public Page<Orders> list(Pageable page) {
		return ordersService.list(page);
	}

	/**
	 * 获取
	 */
	@GetMapping("/{id}")
	public Orders get(@PathVariable("id") Integer id) {
		return ordersService.findById(id);
	}

	/**
	 * 添加
	 */
	@PostMapping("/add")
	public void add(@RequestBody Orders orders) {
		ordersService.save(orders);
	}


	/**
	 * 修改
	 */
	@PostMapping("/update")
	public void update(@RequestBody Orders orders) {
		ordersService.save(orders);
	}


}

